package com.cat.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * @author cat
 * @version 2025/5/27 18:59
 * @description 具体主题角色类
 * @since JDK17
 */

public class SubscriptionSubject implements Subject {
    // 定义一个集合，用于存储所有观察者对象
    private List<Observer> weixinUserList = new ArrayList<>();

    @Override
    public void attach(Observer observer) {
        weixinUserList.add(observer);
    }

    @Override
    public void detach(Observer observer) {
        weixinUserList.remove(observer);
    }

    @Override
    public void notify(String message) {
        weixinUserList.forEach(observer -> observer.update(message));
    }
}
